/*
 * @lc app=leetcode.cn id=46 lang=javascript
 *
 * [46] 全排列
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var permute = function (nums) {
    const res = []
    const path = []

    function backTrack(arr) {
        if (!arr.length) {
            res.push([...path])
            return
        }
        for (let i = 0; i < arr.length; i++) {
            const newArr = [...arr]
            const tmp = newArr.splice(i, 1)[0]
            path.push(tmp)
            backTrack(newArr)
            path.pop()
        }
    }

    backTrack(nums)

    return res
};
// @lc code=end

